# 思路：遍历层数
from collections import deque
from tools.treeNode import Tree


def maxDepth(root):
    if not root:
        return 0
    q = deque()
    q.append(root)
    res = 0
    while len(q):
        size = len(q)
        while size > 0:
            temp = q.popleft()
            if temp.left:
                q.append(temp.left)
            if temp.right:
                q.append(temp.right)
            size -= 1
        res += 1
    return res


root = Tree(1)
root.left = Tree(2)
root.right = Tree(2)
root.left.left = Tree(3)
root.left.right = Tree(4)
root.right.left = Tree(4)
root.right.right = Tree(3)
print(maxDepth(root))
